<template>
	<div class='base-content  page-content  teachTime'>
		<ul class="base-item-tab">
			<li>
				<router-link to="/BaseSetting/teachTime" class="active">教学时间</router-link>
			</li>
			<li>
				<router-link to="/BaseSetting/courseInfo">课程信息</router-link>
			</li>
			<li>
				<router-link to="/BaseSetting/teacher">教师信息</router-link>

			</li>
			<li  v-if="classType==2">
				<router-link to="/BaseSetting/classRoomInfo">教室信息</router-link>
			</li>
			<li v-if="tnId == 66">
				<router-link to="/BaseSetting/courseAndTeach">教师及课时分配</router-link>
			</li>
		</ul>
		<h5 class="title-2">每周上课天数</h5>
		<el-checkbox-group v-model="checkedCities1">
			<el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>

		</el-checkbox-group>
		<h5 class='calssNum'>每天上课节次</h5>
		<span>上午：<el-select v-model="value1" placeholder="请选择">
                         <el-option  v-for="item in options1" :key="item.value" :label="item.label"  :value="item.value">
                        </el-option>

                      </el-select>

                </span>
		<span class='after'> 下午：<el-select v-model="value2" placeholder="请选择">
                        <el-option  v-for="item in options1" :key="item.value" :label="item.label"  :value="item.value">
                       </el-option>

                      </el-select>
                 </span>
		<span class='after'> 晚上：<el-select v-model="value3" placeholder="请选择">
                       <el-option  v-for="item in options" :key="item.value" :label="item.label"  :value="item.value">
                      </el-option>

                     </el-select>
                 </span>
		<button @click="saveTeachTime()" type="button" class="btn-save-base" id="btn-save-base">保存</button>

	</div>

</template>

<script>
	import utils from '@/assets/js/urlConfig.js'
	const cityOptions = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'];
	export default {
		props:['tnId'],
		data() {
				return {
					checkedCities1: [],
					cities: cityOptions,
					taskId: '',
					options: [{
						value: '0',
						label: '0'
					},{
						value: '1',
						label: '1'
					}, {
						value: '2',
						label: '2'
					}, {
						value: '3',
						label: '3'
					}, {
						value: '4',
						label: '4'
					}],
					options1: [{
						value: '1',
						label: '1'
					}, {
						value: '2',
						label: '2'
					}, {
						value: '3',
						label: '3'
					}, {
						value: '4',
						label: '4'
					}, {
						value: '5',
						label: '5'
					}],
					value1: '4',
					value2: '4',
					value3: '0',
					classType:0
				}
			},
			mounted() {
				this.getTeacherList();
			},
			methods: {
				getTeacherList() {

					this.taskId = sessionStorage.getItem('taskId');
					this.classType = sessionStorage.getItem('classType');
					//字符串转为数值
					if(typeof(this.classType)=='string'){
						this.classType = Number(this.classType)
					}
					this.$http.get(utils.UrlConfig.queryTeachTime + '&taskId=' + this.taskId)
						.then(res => {
							res = res.data;
							if(res.rtnCode === "0000000") {
								const teach_Date = res.bizData.teachDate;
								this.checkedCities1 = teach_Date.split('|');

								const teachTimeOption = res.bizData.teachTime;
								const teachTime = teachTimeOption.split('|');
								this.value1 = teachTime[0];
								this.value2 = teachTime[1];
								this.value3 = teachTime[2];
								sessionStorage.setItem('classNum', Number(this.value1) + Number(this.value2) + Number(this.value3));
								sessionStorage.setItem('teachDate', teach_Date)
							} else {
								this.$message.error(res.msg);
							}

						}).catch(error => {
							console.log(error)
						})

				},
				saveTeachTime() {
					const teachDate = this.checkedCities1.join('|');

					const teachTime = this.value1 + '|' + this.value2 + '|' + this.value3

					this.$http.post(utils.UrlConfig.saveTeachTime + "&taskId=" + this.taskId + "&teachDate=" + teachDate + '&teachTime=' + teachTime)
						.then(res => {
							sessionStorage.setItem('classNum', Number(this.value1) + Number(this.value2) + Number(this.value3));
							sessionStorage.setItem('teachDate', teachDate)
							res = res.data;
							if(res.rtnCode === "0000000") {
								this.$message({
									message: '保存成功！',
									type: 'success'
								});

							} else {
								this.$message.error(res.msg);
							}

						}).catch(error => {
							console.log(error)
						})

				}
			}
	}
</script>

<style>
	.base-content {
		padding-left: 0px;
	}
	
	h5 {
		margin-bottom: 15px;
		font-weight: bold;
	}
	
	.calssNum {
		margin-top: 25px;
	}
	
	el-select {
		margin-left: 10px
	}
	
	.after {
		margin-left: 70px;
	}
	
	.teachTime .el-checkbox {
		margin-right: 15px;
	}
	
	.selected {
		background-color: #20a0ff!important;
	}
	
	.teachTime .base-item-tab {
		padding-bottom: 7px;
	}
	
	.teachTime .base-item-tab li+li+li a {
		border-right: 1px solid #D8D8D8!important;
	}
	.teachTime .base-item-tab li:last-child a {
		border-right: 0 !important;
	}
</style>